/**
 * 
 */
package com.taobao.wolfwolf.hibernate.dao.impl;

import java.util.List;


import com.taobao.wolfwolf.hibernate.dao.TypeDao;
import com.taobao.wolfwolf.hibernate.pojo.Type;

/**
 * @author Tux
 *
 * 创建时间: 2011-4-30 上午01:41:33
 */
@SuppressWarnings("unchecked")
public class TypeDaoImpl extends BaseDaoImpl implements TypeDao {

	public Type findById(int id) throws Exception {
		return (Type) getHibernateTemplate().get(Type.class, id);
	}
	
	public List<Type> findByName(String name) throws Exception {
		return super.findByProperty(Type.class, "name", name);
	}

	public List<Type> findAll() throws Exception {
		return getHibernateTemplate().find("from Type");
	}

	public long getTotal() throws Exception {
		return super.countByCriteria(Type.class);
	}

	public List<Type> paging(int page, int limit) throws Exception {
		return super.findByCriteriaByPage(Type.class, page, limit);
	}

	public List<Type> findByCategoryId(int id) throws Exception {
		return this.getHibernateTemplate().find("from Type as t where t.category.id= ? ", id);
	}

	public List<Type> findByCategoryName(String name) throws Exception {
		return this.getHibernateTemplate().find("from Type as t where t.category.name = ? ", name);
	}

	@Override
	public Integer getMaxId() throws Exception {
		return (Integer) getSession().createQuery("select max(id) from Type").uniqueResult();
	}
}
